package com.wenfs.demo.controller;

import com.wenfs.demo.entity.SysRole;
import com.wenfs.demo.service.ISysMenu;
import com.wenfs.demo.service.ISysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author wenfs
 */
@Controller
@RequestMapping("role")
public class RoleController {

  @Autowired
  private ISysRole iSysRole;
  @Autowired
  private ISysMenu iSysMenm;

  @GetMapping("/roleMenu")
  public String roleMenu(String roleCode,Model model) {
    model.addAttribute("roleCode",roleCode);
    model.addAttribute("menus",iSysMenm.findAll());
    return "roleMenu";
  }

  @GetMapping("/findAll")
  public String findAll(Model model) {
    model.addAttribute("roles",iSysRole.findAll());
    return "roleList";
  }


  @PostMapping("/save")
  public String save(SysRole role) {
    iSysRole.save(role);
    return "roleSave";
  }

  @GetMapping("/setStatus")
  public String setStatus(Integer status,String roleCode) {
    iSysRole.setStatus(status,roleCode);
    return "redirect:/role/findAll";
  }

//  @GetMapping("/setPermsToRole")
//  public String setPermsToRole(String roleCode,String[] menuCodes) {
//    iSysRole.setStatus(status,roleCode);
//    return "redirect:/role/findAll";
//  }

}
